//
//  ViewController.m
//  QQ音乐MV界面
//
//  Created by mafeng on 16/8/13.
//  Copyright © 2016年 mafeng. All rights reserved.
//

#import "ViewController.h"
#import "MVTableViewCell.h"
#import "HeadView.h"
#import "AFNetworking.h"
#import "UIButton+WebCache.h"
#import "MVResult.h"
#import "MVData.h"
#import "MVMvlist.h"
#import "MVSinger.h"
#import "MVMvlist.h"
#import "MVMvShowPlay.h"
#import "MVContent.h"
@interface ViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) MVResult *result;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self createHeadView];
    [self getData];
}

  // 创建tableview的头视图
- (void)createHeadView {
    
    NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:@"HeadView" owner:nil options:nil];
  
    HeadView *headView = [nibContents lastObject];
    
    headView.frame = CGRectMake(0, 0, 300, 200);
  
    _tableView.tableHeaderView = headView;
}
 // 用AFNetworking从网络获取数据
- (void)getData {
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *getURL = @"http://i.y.qq.com/v8/fcg-bin/getmv_by_tag?cmd=mv_shows_new&g_tk=5381&uin=0&format=json&inCharset=utf-8&outCharset=utf-8&notice=0&platform=h5&needNewCode=1&_=1470996835294";
    
    // 添加contentd-type: application/x-javascript
     [manager.responseSerializer setAcceptableContentTypes:[NSSet setWithObjects:@"application/x-javascript", nil]];
    [manager GET:getURL parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"请⃣求⃣成⃣功⃣❤️: %@", responseObject);
        self.result = [[MVResult alloc] initWithDictionary:responseObject];
        NSLog(@"********%@", result.data.mvShowPlay);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"请⃣求⃣失⃣败⃣%@", error);
        
    }];
    
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MVTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"tableViewReuse"];
    MVList *list = _result.data.contents.list;
    MVMvlist *mvList = list[indexPath.section];
    cell.topButton sd_setImageWithURL:[NSURL URLWithString:<#(nonnull NSString *)#>] forState:<#(UIControlState)#>
    return cell;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
